import { create } from 'zustand';
import { persist } from 'zustand/middleware';

export interface Customer {
  customerID: number;
  customerName: string;
  PID: string;
  telephone: string;
  address: string;
}

export interface CustomerState {
  customer: Customer | null;
  setCustomer: (customer: Customer | null) => void;
  customerContentKey: string;
  setCustomerContentKey: (key: string) => void;
}

export const useCustomerState = create<CustomerState>()(
  persist(
    (set) => ({
      customer: null,
      customerContentKey: 'home',
      setCustomer: (customer) => set({ customer }),
      setCustomerContentKey: (index) => set({ customerContentKey: index }),
    }),
    {
      name: 'customer-storage',
    },
  ),
);
